﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using ClientLib.MonitorState2;
using WpfDataBingding.UserDefControl;

namespace WpfDataBingding
{
    /// <summary>
    /// DeviceMonitor.xaml 的交互逻辑
    /// </summary>
    public partial class DeviceMonitor : Page
    {
        public DeviceMonitor()
        {
            InitializeComponent();
            InitPage();
        }

       
 //#region  ///测试
 //       public void InitPage()
 //       {
 //           Collection collection=(Collection)Application.Current.Properties["MonitorCollection"];

 //          MonitorDynamic monitor=collection.GetMonitor("agent1");

 //          int num = monitor.GetDeviceNum();

 //          int row = num / 3;

 //          if ((num / 3) != 0)
 //          {
 //              row++;
 //          }

 //          for (int i = 0; i < row; i++)
 //          {
 //              RowDefinition newrow = new RowDefinition();
 //              this.grid_layout.RowDefinitions.Add(newrow);
 //          }
 //          IEnumerable<DeviceDynamic> device_list = monitor.GetDeviceList();

 //          int k1 = 0; int k2 = 0;
 //          foreach (var item in device_list)
 //          {
               
 //              DynamicMonitor user1 = new DynamicMonitor(item);
 //              this.grid_layout.Children.Add(user1);
 //              Grid.SetRow(user1, k1);
 //              Grid.SetColumn(user1, k2);
 //              k2++;

               
 //             if((k2%3)==0)
 //              {
 //                  k1++;
 //                  k2 = 0;
 //              }

 //          }

 //       }
 //       #endregion

        #region
        private void InitPage()
        {
            Collection devcollection= (Collection)Application.Current.Properties["MonitorCollection"];
           IEnumerable<DeviceDynamic> device_list = devcollection.GetDeviceList();
           //int devcount = dev_list.Count();

           int num = device_list.Count();

           int row = num / 3;

           if ((num / 3) != 0)
           {
               row++;
           }

           for (int i = 0; i < row; i++)
           {
               RowDefinition newrow = new RowDefinition();
               this.grid_layout.RowDefinitions.Add(newrow);
           }
         

           int k1 = 0; int k2 = 0;
           foreach (var item in device_list)
           {

               DynamicMonitor2 user1 = new DynamicMonitor2(item);
               this.grid_layout.Children.Add(user1);
               Grid.SetRow(user1, k1);
               Grid.SetColumn(user1, k2);
               k2++;


               if ((k2 % 3) == 0)
               {
                   k1++;
                   k2 = 0;
               }

           }
        }
        #endregion
    }
}
